package com.ql.gamelogm.service.impl;

import com.ql.gamelogm.dao.ManagerDao;
import com.ql.gamelogm.entities.Manager;
import com.ql.gamelogm.entities.RedisCache;
import com.ql.gamelogm.entities.Right;
import com.ql.gamelogm.service.ManagerService;
import com.ql.gamelogm.utils.List2PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class ManagerServiceImpl implements ManagerService{
    @Autowired
    private ManagerDao managerDao;
    @Autowired
    private List2PageUtil list2PageUtil;
    @Override
    public List<Manager> findAllManager() {
        return managerDao.findAllManager();
    }

    @Override
    public List<Manager> findManagerByID(String id) {
        return managerDao.findManagerByID(id);
    }

    @Override
    public boolean updatePwd(String pwd, String id) {
        return managerDao.updatePwd(pwd,id);
    }

    @Override
    public boolean updatenPwd(String pwd, String email) {
        return managerDao.updatenPwd(pwd,email);
    }

    @Override
    public boolean addManager(Manager manager) {
        return managerDao.addManager(manager);
    }

    @Override
    public boolean updateManager(Manager manager,String id) {
        return managerDao.updateManager(manager,id);
    }

    @Override
    public boolean deleteManager(String id) {
        return managerDao.deleteManager(id);
    }

    @Override
    public Page<Manager> getManager(int pageNum, int pageSize) {
        Pageable pageable= PageRequest.of(pageNum,pageSize);
        List<Manager> managerList=managerDao.findAllManager();
        return list2PageUtil.listConvertToPage(managerList,pageable);
    }

    @Override
    public List<Right> findAllManagerRight() {
        return managerDao.findAllManagerRight();
    }

    @Override
    public List<Right> findRightById(String id) {
        return managerDao.findRightById(id);
    }

    @Override
    public boolean addRight(Right right) {
        return managerDao.addRight(right);
    }

    @Override
    public boolean updateRight(Right right, String id) {
        return managerDao.updateRight(right,id);
    }

    @Override
    public boolean deleteRightById(String id) {
        return managerDao.deleteRightById(id);
    }

    @Override
    public Page<Right> getRights(int pageNum, int pageSize) {
        Pageable pageable= PageRequest.of(pageNum,pageSize);
        List<Right> rightList=managerDao.findAllManagerRight();
        List<Right> rightList1=new ArrayList<Right>();
        for(int i=0;i<rightList.size();i++){
            if(rightList.get(i).getManagerType().equals("管理员")){
                rightList1.add(rightList.get(i));
            }
        }
        return list2PageUtil.listConvertToPage(rightList1,pageable);
    }


}
